package com.agv.core.daoImpl;

import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.agv.core.dao.ClienteDAO;
import com.agv.core.dao.exception.QueryDAOException;
import com.agv.core.dao.mapper.ClienteMapper;
import com.agv.dto.ClienteDTO;

public class ClienteDAOImpl extends JdbcDaoSupport implements ClienteDAO{
	
	public ClienteDTO getIdClientebyCod_Cliente(String codCliente)
	throws QueryDAOException {
		try {
			return (ClienteDTO) getJdbcTemplate().queryForObject(
					CONSULTA_CLIENTE, new Object[] { codCliente },
					new ClienteMapper());
		
		} catch (EmptyResultDataAccessException erdae) {
			return null;
		
		} catch (DataAccessException dae) {
			throw new QueryDAOException("Error al consultar un cliente", dae);
		}
	}
	final String CONSULTA_CLIENTE = 
		"SELECT id_org, cd_cliente, id_cte, nb_cliente, nb_comer_cte, rfc_cliente,"+ 
			"activo, pagina, id_usuario_act_ant, fh_act_ant, campo_act, id_usuario_ult_act,"+ 
			"fh_ult_act, id_usuario_crc, fh_creacion "+
		"FROM cxc.t001_cxc_cfg_clientes where cd_cliente= ?";
		
}
